package com.tanhua.server.rmq;


import com.alibaba.fastjson.JSON;
import com.tanhua.dubbo.api.QuestionnaireApi;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class DeleteReport {


    @DubboReference
    private QuestionnaireApi questionnaireApi;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(
                    value = "tanhua.log.deleteReport"
            ),
            exchange = @Exchange(
                    value = "tanhua.log.exchange",
                    type = ExchangeTypes.TOPIC
            ),
            key = "log.delete.report"
    ))

    public void deleteReport(String message) {
        System.out.println("开始删除");
        Map<String, String> map = JSON.parseObject(message, Map.class);
        Long userId = Long.valueOf(map.get("userId"));
        String level = (String) map.get("type");
        String reportId=(String)map.get("busId");
        questionnaireApi.deleteSimilar(userId,level);
        //删除以前的报告维度值
        questionnaireApi.deleteExtra(Integer.valueOf(reportId));

    }
}
